package com.guinea.skosite.web;

// Generated 2011-3-15 19:06:13 by Hibernate Tools 3.4.0.Beta1

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.guinea.core.Constants;
import com.guinea.core.orm.Page;
import com.guinea.core.orm.PropertyFilter;
import com.guinea.core.web.StrutsAction;
import com.guinea.skoru.service.SkoruTownManager;

public class SkositeTownAction extends StrutsAction {

	private SkoruTownManager skoruTownManager;

	public SkoruTownManager getSkoruTownManager() {
		return skoruTownManager;
	}

	public void setSkoruTownManager(SkoruTownManager skoruTownManager) {
		this.skoruTownManager = skoruTownManager;
	}
	/**
	 * url参数未定义method时的默认Action函数. 默认为index Action.
	 */
	public ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		return list(mapping, form, request, response);
	}
	/**
	 * 列出所有对象的Action函数.
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		List filters = PropertyFilter.buildFromHttpRequest(request);
		Page page = PropertyFilter.buildPageFromHttpRequest(request,"page");
		//设置默认排序方式
		if (!page.isOrderBySetted()) {
			page.setOrderBy("id");
			page.setOrder(Page.ASC);
		}
		//设置默认查询条件
		PropertyFilter filter = new PropertyFilter(Constants.FILTER_NAME, Constants.STATUS_VALID);
		filters.add(filter);
		page = getSkoruTownManager().findPage(page, filters);
		request.setAttribute("page", page);
		return mapping.findForward("list");
		
	}
}
